package demo02;

/**
 * @author: WangPeng
 * @createTime: 2022/11/03 17:18
 * @description:
 * @version: v1.0
 */
public class Test02 {
    public static void main(String[] args) {
        //形参列表只有一个参数可以省略括号，直接写参数名即可
        Operator operator =(arr)->{
            int sum=0;
            for (int i : arr) {
                sum+=i;
            }
            return sum;
        };
        fun(operator);
    }

    public static void fun(Operator operator){
        int sum[] = {1,2,3,4} ;
        int sum1 = operator.getSum(sum);
        System.out.println("数组元素的和："+sum1);
    }
}
//自定义有参有返回值的函数式接口
@FunctionalInterface
interface Operator {
    public int getSum(int[] arr);
}